import { createRouter, createWebHistory } from "vue-router";
import NProgress from "nprogress";
import "nprogress/nprogress.css";
import container from "./container";
import notLoggedIn from "./notLoggedIn"
import { useSystemStore } from "@/store/system";

const router = createRouter({
  history: createWebHistory(),
  routes: notLoggedIn
});


// 前置路由守卫
router.beforeEach((to, from, next) => {
  // NProgress.start();
  // window.scrollTo(0, 0); // 跳转后置顶
  // 判断登录权限
  const systemStore = useSystemStore();
  console.log('to.meta.requireAuth',useSystemStore())
  if (to.meta.requireAuth) {
    if (systemStore.isLogin == true) {
      next();
    } else {
      next("/touristHomepage");
    }
  } else {
    if (to.path === "/touristHomepage") {
      systemStore.logOut();
    }
    next();
  }
});

// 后置路由守卫
// router.afterEach(() => {
//   NProgress.done();
// });

export default router;
